package teaching.tools;

import java.util.Random;

import teaching.data.LearningSet;
import teaching.data.Vecteur;

public class ArtificialLearningSet
{

	/**
	 * 
	 * @param x0 X du centre de la distribution 0
	 * @param y0 Y du centre de la distribution 0
	 * @param var0 X du centre de la distribution 0
	 * @param x1 X du centre de la distribution 1
	 * @param y1 Y du centre de la distribution 1
	 * @param var1 X du centre de la distribution 1
	 * @param nb_points Nombre de points
	 * @return
	 */
	
	public static LearningSet generateGaussian2DBinaryLearningSet(double x0,double y0,double var0,double x1,double y1,double var1,int nb_points)
	{
		Random r=new Random();
		LearningSet ls=new LearningSet();
		while(ls.size()<nb_points)
		{
			Vecteur v=new Vecteur(2);
			
			if (r.nextGaussian()<0)
			{
				double t=r.nextGaussian();
				t=t*var0+x0;
				v.setValue(0,t);
				
				t=r.nextGaussian();
				t=t*var0+y0;
				v.setValue(1,t);	
				ls.add(v, -1);
			}
			else
			{
				double t=r.nextGaussian();
				t=t*var1+x1;
				v.setValue(0,t);
				
				t=r.nextGaussian();
				t=t*var1+y1;
				v.setValue(1,t);	
				String cat="Class 1";						
				ls.add(v, +1);
			}
			
		}
		return(ls);
			
	}
	
	
	public static LearningSet generateBiGaussian2DBinaryLearningSet(double x0,double y0,double var0,double x1,double y1,double var1,int nb_points)
	{
		Random r=new Random();
		LearningSet ls=new LearningSet();
		while(ls.size()<nb_points)
		{
			Vecteur v=new Vecteur(2);
			
			if (r.nextGaussian()<0)
			{
				if (r.nextGaussian()<0)
				{
					double t=r.nextGaussian();
					t=t*var0+x0;
					v.setValue(0,t);
				
					t=r.nextGaussian();
					t=t*var0+y0;
					v.setValue(1,t);	
					ls.add(v, -1);
				}
				else
				{
					double t=r.nextGaussian();
					t=t*var0+x1;
					v.setValue(0,t);
					
					t=r.nextGaussian();
					t=t*var0+y1;
					v.setValue(1,t);	
					String cat="Class 1";						
					ls.add(v, -1);
				}
			}
			else
			{
				if (r.nextGaussian()<0)
				{
					double t=r.nextGaussian();
					t=t*var1+x1;
					v.setValue(0,t);
				
					t=r.nextGaussian();
					t=t*var1+y0;
					v.setValue(1,t);	
					ls.add(v, +1);
				}
				else
				{
					double t=r.nextGaussian();
					t=t*var1+x0;
					v.setValue(0,t);
					
					t=r.nextGaussian();
					t=t*var1+y1;
					v.setValue(1,t);	
					String cat="Class 1";						
					ls.add(v, +1);
				}
			}
			
		}
		return(ls);
			
	}
}
